package com.wlwx.simulator.message.inbound;

import com.wlwx.simulator.codec.CMPPCommand;
import com.wlwx.simulator.message.basic.BaseInBoundMessage;

import java.nio.ByteBuffer;

public class LoginInBoundRequest extends BaseInBoundMessage {

    // 6byte
    private String sourceAddr;

    // 16byte
    private String authAddr;


    private byte version;

    // 4byte
    private int timestamp;

    public LoginInBoundRequest() {
        super(CMPPCommand.CMPP_LOGIN_REQ_COMMAND);
    }

    public void decode(ByteBuffer byteBuffer) {
        byte[] bytes = new byte[6];
        byteBuffer.get(bytes);
        sourceAddr = new String(bytes);

        bytes = new byte[16];
        authAddr = new String(bytes);

        version = byteBuffer.get();

        timestamp = byteBuffer.getInt();
    }

    public String getSourceAddr() {
        return sourceAddr;
    }

    public void setSourceAddr(String sourceAddr) {
        this.sourceAddr = sourceAddr;
    }

    public String getAuthAddr() {
        return authAddr;
    }

    public void setAuthAddr(String authAddr) {
        this.authAddr = authAddr;
    }

    public byte getVersion() {
        return version;
    }

    public void setVersion(byte version) {
        this.version = version;
    }

    public int getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer("CMPP20 Login : [")
                .append("sourceAddr : ").append(sourceAddr).append(", ")
                .append("authAddr : ").append(authAddr).append(", ")
                .append("version : ").append(version).append(", ")
                .append("timestamp : ").append(timestamp)
                .append("]");
        return sb.toString();

    }
}
